package com.truth.lock.configure.redistemplate;

import com.truth.lock.configure.TruthLockProperties;
import com.truth.lock.executor.TruthLockExecutor;
import com.truth.lock.executor.redistemplate.RedisTemplateLockExecutor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @author truth
 */
@Configuration
@EnableConfigurationProperties(TruthLockProperties.class)
@ConditionalOnBean(type = {"org.springframework.data.redis.core.StringRedisTemplate"})
@ConditionalOnProperty(prefix = "truth.lock", name = "lock-type", havingValue = "redis_template")
public class RedisTemplateAutoConfiguration {

    @Bean
    @ConditionalOnBean(type = {"org.springframework.data.redis.core.StringRedisTemplate"})
    public TruthLockExecutor<String> redisTemplateLockExecutor(StringRedisTemplate stringRedisTemplate) {
        return new RedisTemplateLockExecutor(stringRedisTemplate);
    }

}
